package com.example.rpcdemo.registry;

import java.util.Objects;

public class ServiceInstance {
    private final String serviceName;
    private final String interfaceName;
    private final String host;
    private final int port;
    private final String address;
    private final long timestamp;
    
    public ServiceInstance(String serviceName, String interfaceName, String host, int port) {
        this.serviceName = serviceName;
        this.interfaceName = interfaceName;
        this.host = host;
        this.port = port;
        this.address = host + ":" + port;
        this.timestamp = System.currentTimeMillis();
    }
    
    public String getServiceName() {
        return serviceName;
    }
    
    public String getInterfaceName() {
        return interfaceName;
    }
    
    public String getHost() {
        return host;
    }
    
    public int getPort() {
        return port;
    }
    
    public String getAddress() {
        return address;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        ServiceInstance that = (ServiceInstance) obj;
        return port == that.port && 
               host.equals(that.host) && 
               serviceName.equals(that.serviceName);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(serviceName, host, port);
    }
    
    @Override
    public String toString() {
        return "ServiceInstance{" +
               "serviceName='" + serviceName + '\'' +
               ", interfaceName='" + interfaceName + '\'' +
               ", address='" + address + '\'' +
               ", timestamp=" + timestamp +
               '}';
    }
}